package user_information;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;

import DB.DB_connection_pool;

public class User_data extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		
		PrintWriter out = response.getWriter();
		String user_account = request.getSession().getAttribute("user_account").toString();
		
		String select_user_data = "select * from user_data where user_account = '"+user_account+"'";
		JSONObject jsonObj = new JSONObject();
		
		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps_select= conn.prepareStatement(select_user_data);
			ResultSet rs = ps_select.executeQuery();
		
			if(rs.next()){
				jsonObj.put("user_account", rs.getString("user_account"));                        //用户账号
				jsonObj.put("user_nickname", rs.getString("user_nickname"));                    //用户昵称
				jsonObj.put("user_birthday", rs.getDate("user_birthday"));                        //用户生日
				jsonObj.put("user_birth_place", rs.getString("user_birth_place"));               //用户出生地
				jsonObj.put("user_qq", rs.getString("user_qq"));                               //用户qq
				jsonObj.put("user_photo_path", rs.getString("user_photo_path"));                //用户头像URL
				jsonObj.put("user_hobby", rs.getString("user_hobby"));                          //用户业余爱好
				jsonObj.put("user_introduction", rs.getString("user_introduction"));                    //用户个人简介
				jsonObj.put("password_protect_1", rs.getString("password_protect_1"));                   //用户密保问题一
				jsonObj.put("password_protect_answer_1", rs.getString("password_protect_answer_1"));      //用户密保问题一（答案）
				jsonObj.put("password_protect_2", rs.getString("password_protect_2"));                    //用户密保问题二
				jsonObj.put("password_protect_answer_2", rs.getString("password_protect_answer_2"));     //用户密保问题二（答案）
				jsonObj.put("password_protect_3", rs.getString("password_protect_3"));                   //用户密保问题三
				jsonObj.put("password_protect_answer_3", rs.getString("password_protect_answer_3"));   //用户密保问题三（答案）
				jsonObj.put("is_email_checking", rs.getInt("is_email_checking"));             //用户邮箱是否验证
				jsonObj.put("Is_telephone_checking", rs.getInt("is_telephone_checking"));    //用户电话是否验证
				jsonObj.put("user_level", rs.getInt("user_level"));      //用户等级
				jsonObj.put("user_integral", rs.getDouble("user_integral"));    //用户积分
				jsonObj.put("user_sex", rs.getString("user_sex"));    //用户性别
	
				jsonObj.put("result", true);
			}else{
				jsonObj.put("result", false);
			}
			
			rs.close();
			ps_select.close();
			conn.close();
			
		} catch (SQLException e) {
			jsonObj.put("result", false);
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		out.print(jsonObj.toString());
		
	}

}
